package com.itheima.day10.第三题;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

/*
*   顺序列表ArrayList中存储了如下字符串
*       ["hehe", "haha", "heihei", "gege", "gaga"]
*       请使用迭代器遍历集合，按顺序输出元素。
* */
public class Demo3 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"hehe", "haha", "heihei", "gege", "gaga");

        //创建一个迭代器
        Iterator<String> it = list.iterator();
        //遍历打印
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }
}
